package com.scott;


/**
 * @author 黄后林
 * @version 1.0
 * @note
 * @date 2022-03-13 18:27:29
 */
public class T06 {

    public static void main(String[] args) {

        int n = 5;
        int v = 4;
        int[] a ={1,2,4,4,5};

        System.out.println(upper_bound_(n,v,a));;


    }

    /**
     * 方法描述:
     * @author: 黄后林
     * @date: 2022/3/13 18:33 
     * @param n 数组长度
     * @param v 查找值
     * @param a 整型一维数组 有序数组
     * @return int
     */
    public static int upper_bound_ (int n, int v, int[] a) {
        // write code here
        int low = 0, high = n-1;
        while(low < high){
            int mid = low + (high - low) / 2;
            if(a[mid] < v){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }

        return a[low] >= v ? low + 1 : n + 1;
    }
}
